const app = getApp()
import {imageUrl} from "../../utils/imageutil.js"
Page({
  data: {
    imageUrl:imageUrl,
    recommendPage:1,
    recommendFlag:true,
    recommendList:[],
    store_id:'',
    company_type:'',
  },
  onLoad: function (options) {
    this.setData({
      company_type:options.company_type,
      store_id:options.store_id
    })
    if(options.typename){
      wx.setNavigationBarTitle({
        title: options.typename
      })
    }
    this.getRecommend();
  },
  onPullDownRefresh(){
    this.setData({
      recommendPage:1,
      recommendFlag:true,
      recommendList:[],
    })
    this.getRecommend();
  },
  onReachBottom(){
    if(this.data.recommendFlag){
      this.getRecommend();
    }
  },
  getRecommend(){
    if(!this.data.recommendFlag){
      return
    }
    app.globalData.post({
      data:{
        do: 'DishesListNew',
        // store_id:this.data.store_id,
        company_type:this.data.company_type,
        page:this.data.recommendPage,
        pagesize:10
      }
    }).then(res=>{
      wx.stopPullDownRefresh();
      if(res.data.data.length==0){
        this.setData({
          recommendFlag:false
        })
      }else{
        let arr = this.data.recommendList.concat(res.data.data);
        this.setData({
          recommendList:arr,
          recommendPage:this.data.recommendPage+1
        })
      }
    })
  },
  to_projects(e){
    wx.navigateTo({
      url: '../projects/index?good_id='+e.currentTarget.dataset.id,
    })
  },
})